package com.jeomo.common.quartz.starter.jobs;

import com.jeomo.common.quartz.starter.entity.JobParameter;
import com.jeomo.common.quartz.starter.service.BaseJob;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * <h3>springboot-quartz</h3>
 * 为job加上@DisallowConcurrentExecution注解后job执行就会阻塞，
 * 在上一次job执行完毕后再去执行下一次job
 * 如果没加上@DisallowConcurrentExecution注解只要到了触发器触发的时间，就会执行一次job，
 *
 * @author : 崔贺
 * @date : 2020-08-18
 **/

public class HelloJob implements BaseJob {

    private static Logger log = LoggerFactory.getLogger(HelloJob.class);

    public HelloJob() {

    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("Hello Job执行时间: " + new Date());
        //*注意！！！* trigger和jobDetail都可以传递参数，这里使用的是trigger传递参数
        JobDataMap jobDataMap = context.getTrigger().getJobDataMap();
        JobParameter jobParameter = (JobParameter) jobDataMap.get(JobParameter.JOB_PARAM);
        log.info("我传参啦key1" + "******:" + jobParameter.getKey1());
        log.info("我传参啦key2" + "******:" + jobParameter.getKey2());
        log.info("我传参啦key3" + "******:" + jobParameter.getKey3());
        System.out.println("立即执行" + new Date());
//        System.out.println("当前任务的执行时间" + context.getFireTime());
//        System.out.println("下一次任务的执行时间" + context.getNextFireTime());
    }
}
